/**
 * @Author: leibidong
 * @Description: 二级类目管理
 * @File:  secondCategoryHandler
 * @Version: 1.0.0
 * @Date: 2021/7/4 20:13
 */

package handler

import (
	"fmt"
	"ginProject/biz/service"
	"ginProject/biz/utils"
	"ginProject/biz/vo"
	"github.com/gin-gonic/gin"
)

/**
 * @Author leibidong
 * @Description 根据用户输入一级分类名称查询所有二级类目
 * @Date  2021/7/4 21:23
 **/
func SelectAllSecondCategory(c *gin.Context) {
	firstName := c.Query("firstName")
	answer := service.SelectAllSecondCategory(firstName)
	if answer == nil {
		utils.ReturnFailureMessage(nil, c)
	} else {
		utils.ReturnOKMessage(answer, c)
	}
}

/**
 * @Author leibidong
 * @Description 添加二级商品类目名称
 * @Date  2021/7/4 21:56
 **/
func AddSecondCategory(c *gin.Context) {
	var second vo.AddSecondName
	c.ShouldBind(&second)
	fmt.Println("参数为", second.FirstName, second.SecondName)
	status := service.AddSecondProductCategory(second.FirstName, second.SecondName)
	if status == 1 {
		utils.ReturnOKMessage("ok", c)
	} else {
		utils.ReturnFailureMessage("没有找到该一级商品目录", c)
	}
}

/**
 * @Author leibidong
 * @Description 更新商品二级类目名称
 * @Date  2021/7/4 21:57
 **/
func UpdateSecondProductCategory(c *gin.Context) {
	var updateName vo.UpdateSecondName
	c.ShouldBind(&updateName)
	status := service.UpdateSecondProductCategory(updateName)
	if status == 0 {
		utils.ReturnFailureMessage("二级类目id无法查找到以及类目名称", c)
	} else {
		utils.ReturnOKMessage("ok", c)
	}
}

/**
 * @Author leibidong
 * @Description 删除产品信息
 * @Date  2021/7/11 17:36
 **/
func DeleteSecondProductCategory(c *gin.Context) {
	secondId := c.Query("id")
	id := utils.StringToInt(secondId)
	status := service.DeleteSecondCategory(id)
	if status == 0 {
		utils.ReturnFailureMessage("二级类目id无法查找到以及类目名称", c)
	} else {
		utils.ReturnOKMessage("ok", c)
	}
}
